

export default class Image {
  constructor(props) {
    let { src, width, height, left, top, isAdapt} = props;

    this.sprite = new PIXI.Sprite.fromImage(src);

    if (width) {
      const scale = width / this.sprite.width;
      this.sprite.width = width;
      if (isAdapt) {
        this.sprite.height = this.sprite.height * scale;
      }
    }
    if (height) {

      const scale = height / this.sprite.height;
      this.sprite.height = height;
      if (isAdapt && this.sprite.height > height) {
        this.sprite.width = this.sprite.width * scale;
      }
    }

    if (left) this.sprite.x = left;
    if (top) this.sprite.y = top;

    return this.sprite;
  }
}
